<template>
	<view class="footer f12 cflex gap5 safe_buttom" :style="'color:' + app.global.thirdTextColor + ';'">
		<view class="dflex gap12 jcc">
			<text>常见问题</text>
			<text @click="openOnlineHelp">人工客服</text>
		</view>
		<text @click="getOtherCode">{{ app.global.appName }} | Version: {{ app.global.version }}</text>	
		
	</view>
</template>

<script>
	const global = getApp().globalData;
	
	export default {
		name: "appFooter",
		data() {
			return {
				app :{
					name : global.appName,
					windowInfo : '',
					HeaderWidth : '',
					global : global
				},
				cos: global.imgUrlPrefix,
				domain: global.domain,
				clickNum : 0,
				helper_id : ''
			};
		},
		onReady: function() {
			this.checkUpdate()
		},
		methods: {
			getOtherCode() {
				this.clickNum++
				if (this.clickNum > 5) {
					// console.log('gogogo')
					uni.request({
						url: this.domain + 'api/v1/getOtherCode',
						method: 'POST',
						data: {
							key: uni.getStorageSync("code_key")
						},
						success: (res) => {
							uni.showToast({
								title: res.data.code,
								icon: 'none'
							})
						},
						fail: (res) => {}
					})
				}
			},
			closewOnlineHelp () {
				this.showOnlineHelp = false
			},
			openOnlineHelp() {				
				uni.showLoading({
					title:'加载中...'
				})
				uni.request({
					// #ifdef MP-WEIXIN
					url : this.domain + 'api/v1/system/wx_helper',
					// #endif
					// #ifdef MP-TOUTIAO
					url : this.domain + 'api/v1/system/dy_helper',
					// #endif
					method : "GET",
					success : (res) => {
						uni.hideLoading()
						// #ifdef MP-WEIXIN
						this.helper_id = res.data.wx_helper
						uni.showModal({
							title: '在线客服',
							content: '联系客服请添加微信号：' + this.helper_id,
							confirmText: '复制号码',
							success: (res) => {
								if(res.confirm) {
									uni.setClipboardData({									
										data: this.helper_id,
										success: () => {
											uni.showToast({
												title: '复制成功，快去微信添加吧！',
												duration: 2000,
												icon: 'none'
											})
										}
									})
								}
							}
						});
						// #endif
						// #ifdef MP-TOUTIAO
						this.helper_id = res.data.dy_helper
						uni.showModal({
							title: '在线客服',
							content: '联系客服请拨打：' + this.helper_id,
							confirmText: '复制号码',
							success: res => {
								if(res.confirm) {
									uni.setClipboardData({									
										data: this.helper_id,
										success: () => {
											uni.showToast({
												title: '复制成功',
												duration: 2000,
												icon: 'none'
											})
										}
									})
								}
							}
						});
						// #endif
					}
				})
			},
			checkUpdate() {
				const updateManager = wx.getUpdateManager()

				updateManager.onCheckForUpdate(function(res) {
					// 请求完新版本信息的回调
					console.log('检测最新版本', res)
				})

				updateManager.onUpdateReady(function() {
					wx.showModal({
						title: '更新提示',
						content: '新版本已经准备好，是否重启应用？',
						success(res) {
							if (res.confirm) {
								// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
								updateManager.applyUpdate()
							}
						}
					})
				})

				updateManager.onUpdateFailed(function() {
					// 新版本下载失败
				})
			}
		}
	}
</script>

<style>
	.footer {
		display: flex;
		flex-direction: column;
		align-items: center;
		color: #aaa;
		margin-top: 20px;
		/* padding-bottom: 15px; */
	}

	.footer text {
		line-height: 20px;
	}
</style>